package app.qrcode.browser.hearttoheart.fragments

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import app.qrcode.browser.hearttoheart.R
import app.qrcode.browser.hearttoheart.activities.MyPrepareActivity
import app.qrcode.browser.hearttoheart.activities.MyResourseActivity
import app.qrcode.browser.hearttoheart.activities.PrepareTeacherActivity
import app.qrcode.browser.hearttoheart.adapters.Images
import app.qrcode.browser.hearttoheart.adapters.ImagesAdapter
import app.qrcode.browser.hearttoheart.databinding.FragmentLessonPrepareBinding
import com.youth.banner.indicator.CircleIndicator
import kotlinx.android.synthetic.main.fragment_lesson_prepare.*


// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER

/**
 * A simple [Fragment] subclass.
 * Use the [LessonPrepareFragment.newInstance] factory method to
 * create an instance of this fragment.
 */
class LessonPrepareFragment : Fragment() {
    private var _binding: FragmentLessonPrepareBinding? = null

    // This property is only valid between onCreateView and
    // onDestroyView.
    private val binding get() = _binding!!

    var imageList: MutableList<Images> = mutableListOf()

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        _binding = FragmentLessonPrepareBinding.inflate(inflater, container, false)
        val root: View = binding.root
        initBanner(imageList)
        useBanner()
        binding.resourceShareBtn.setOnClickListener {
            val intent = Intent(context, MyResourseActivity::class.java)
            startActivity(intent)
        }
        binding.myPrepareBtn.setOnClickListener {
            val intent = Intent(context, MyPrepareActivity::class.java)
            startActivity(intent)
        }
        binding.teacherLegendBtn.setOnClickListener {
            val intent = Intent(context, PrepareTeacherActivity::class.java)
            startActivity(intent)
        }

        return root
    }

    fun useBanner() {
        binding.banner.addBannerLifecycleObserver(this)
            .setAdapter(ImagesAdapter(imageList))
            .setIndicator(CircleIndicator(context))
    }

    fun initBanner(imageList: MutableList<Images>) {
        imageList.add(Images(R.mipmap.lunbo7))
        imageList.add(Images(R.mipmap.lunbo8))
    }
}